package com.oyb.servlet;

import com.oyb.entity.Course;
import com.oyb.entity.Page;
import com.oyb.service.CourseService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/coursequerypage")
public class Coursequerypage extends HttpServlet {
    private CourseService courseService = new CourseService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String page = req.getParameter("page");
        String pagesize = req.getParameter("pagesize");
        if(page == null || pagesize == null){
            page ="1";
            pagesize="3";
        }
        Page p = new Page();
        p.setPage(Integer.parseInt(page));
        p.setPageSize(Integer.parseInt(pagesize));

        try {
            p = courseService.querycourses(p);
            req.setAttribute("page",p);
            req.getRequestDispatcher("coursequery.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }


    }
}
